package work;

import java.util.Random;
import java.util.Scanner;

public class CharDemo {
    public static void main(String[] args) {
        String string = "123456789";

        /*String s = null;
        String a = "bbb";
        s = s +a;
        System.out.println(s);*/

        //创建四位的验证码
        String str = "0123456789qwertyuiopasdfghjklzxcvbnm";
        Random random = new Random();
        int num =4;
        while(true){
            String yzm = "";
            for(int i=1;i<=num;i++){
                int index = random.nextInt(str.length());
                char c = str.charAt(index);
                yzm += c;
            }
            System.out.println("验证码是："+yzm);

            System.out.println("请输入验证码：");
            Scanner scan = new Scanner(System.in);
            String line = scan.nextLine();
            String lowerLine = line.toLowerCase();
            if(yzm.equals(lowerLine)){
                System.out.println("验证码正确");
                break;
            }else{
                System.out.println("验证码输入错误");
            }
        }
    }
}
